<template>
	<div class="page-wrap">
		<div class="page-inner">
			<div class="page-table-ctx-wrap">
				<!-- 控制器 -->
				<div class="actions-box">
					<div class="control-box">
						<div class="control-left">
							<div class="control-item">
								<!-- <el-button type="primary" @click="doAdd()">
									添加
								</el-button> -->
							</div>
						</div>
						<div class="control-right">
							<div class="action-item">
								<el-date-picker v-model="time_range" type="daterange" align="right" unlink-panels
									range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
									value-format="yyyy-MM-dd" :picker-options="pickerOptions">
								</el-date-picker>
							</div>
							<div class="action-item">
								<el-select clearable="" v-model="searchParams.status" placeholder="状态筛选"
									@change="select_status_onchange">
									<el-option v-for="item in status_select_options" :key="item.value"
										:label="item.title" :value="item.value">
									</el-option>
								</el-select>
							</div>
							<div class="action-item">
								<el-input clearable="" v-model="searchParams.keyword" placeholder="请输入关键词">
									<!-- <el-button slot="append" size="small" icon="el-icon-search" @click="doSearch()">
									</el-button> -->
								</el-input>
							</div>
							<div class="action-item">
								<el-button type="primary" @click="doSearch()">
									筛选
								</el-button>
							</div>
						</div>
					</div>
				</div>
				<!-- 控制器 -->

				<!-- 渲染表格 -->
				<div class="table-view">
					<w_table ref="w_table" @emitTable="emitTable" />
				</div>
				<!-- 渲染表格 -->
				<div class="table-util">
					<div class="util-left">
						<!-- 批量选择 -->
					</div>
					<div class="util-right">
						<div class="pagi-item">
							<w_pagination v-if="tableData.length" :total="total" :pagination="pagination"
								@size-change="onSizeChange" @current-change="onCurrentChange" />
						</div>
					</div>
				</div>
			</div>
		</div>


		<!-- <w_form_modal ref="w_form_modal" @confirm="confirmFormSubmit" /> -->


		<invoice_form_modal ref="invoice_form_modal" @confirm="confirmInvoice" />
		<invoice_detail_modal ref="invoice_detail_modal" @confirm="confirmInvoice" />


		<w_detail_modal ref="w_detail_modal" @confirm="confirmInvoice" />
	</div>
</template>

<script>
import w_detail_modal from '@/components/base/w_detail_modal.vue'
import invoice_form_modal from '@/components/order/invoice/invoice_form_modal.vue'
import invoice_detail_modal from '@/components/order/invoice/invoice_detail_modal.vue'
import page_config from "@/constant/order/invoice/invoice-list.js";
import page_mixin from "@/mixins/page_mixin.js";
export default {
	name: "review-list",
	mixins: [page_mixin],
	components: {
		invoice_form_modal,
		invoice_detail_modal,
		w_detail_modal,
	},
	data() {
		return {
			page_config,

			params_delete: {
				updateType: 1, //	操作 1-删除 2-设置推荐 3-取消推荐
			},


			searchParams: {
				page: 1,
				pageNum: 10,
				status: '', //状态：1-待开票 2已开票 -1 已作废
				keyword: '',
				startTime: '',
				endTime: '',
			},
			status_select_options: [{
				title: '全部状态',
				value: '',
			},
			{
				title: '待开票',
				value: 1,
			},
			{
				title: '已开票',
				value: 2,
			},
			{
				title: '已作废',
				value: -1,
			},
			],
			//
			time_range: [],
			pickerOptions: {
				disabledDate(time) {
					return time.getTime() > Date.now();
				},
				shortcuts: [{
					text: "最近一周",
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit("pick", [start, end]);
					},
				},
				{
					text: "最近一个月",
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
						picker.$emit("pick", [start, end]);
					},
				},
				{
					text: "最近三个月",
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
						picker.$emit("pick", [start, end]);
					},
				},
				],
			},
		};
	},
	computed: {

	},
	watch: {
		time_range(value) {
			console.log('time_range', value)
			if (value && value.length) {
				this.searchParams.startTime = this.time_range[0] || ''
				this.searchParams.endTime = this.time_range[1] || ''
			} else {
				this.searchParams.startTime = ''
				this.searchParams.endTime = ''
			}
		}
	},
	created() {

	},
	mounted() {

	},
	methods: {
		doRowOther(row, action_title) {
			console.log('其它操作')
			if (action_title == '详情') {
				this.$refs.invoice_detail_modal.init(row)
			} else if (action_title == '发票开具') {
				this.$refs.invoice_form_modal.init(row)
			} else if (action_title == '发票作废') {
				this.do_invoice_cancel(row)
			}
		},

		//发票作废
		do_invoice_cancel(row) {
			this.$api({
				url: '/admin_service.php',
				method: "get",
				data: {
					action: "users_invoiceCancel",
					id: row.id,
				},
			}).then((res) => {
				if (res.code == 200) {
					this.setView();
					this.$message({
						message: res.msg,
						type: 'success'
					})
				} else {
					alertErr(res.msg)
				}
			});
		},

		confirmInvoice() {
			this.setView()
		},

		select_status_onchange() {
			this.initQuery()
		}
	},
};
</script>

<style scoped lang="less">
// /deep/ .el-table table {
//   width: 100% !important;

//   thead {
//     th.el-table__cell {
//       background: #f8f8f8;
//       color: #000;
//     }
//   }
// }


.page-table-ctx-wrap {
	background: #fff;
	padding: 20px;
	border-radius: 6px;
}

// 新增
.control-box {
	.flex-between();

	.control-left {
		.flex();

		.control-item {
			margin-right: 10px;
		}
	}

	.control-right {
		.flex();

		.action-item {
			margin-left: 10px;
		}
	}
}

.table-view {
	margin-top: 20px;
	margin-bottom: 20px;
}


// 表格工具栏
.table-util {
	.flex-between();

	.util-left {
		.flex();
		min-width: 100px;

		.util-items {
			.flex();

			.item {
				margin-right: 10px;
			}
		}
	}

	.util-right {}
}
</style>